package com.zmn.oms.task.listener;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.business.interfaces.work.tag.OrderTagBService;
import com.zmn.oms.common.constant.MessageQueueTagConsts;
import com.zmn.oms.common.constant.OrderLogConsts;
import com.zmn.oms.common.dto.QueueOrderNodeNotifyDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author sunlife
 * @date:2021/8/18 11:42 上午
 * description:
 */
@Slf4j
@AliyunMQListener(topic = "${spring.mq.topic.oms}")
@Component
public class OrderWorkTagChangeListener {

    @Autowired
    private OrderTagBService orderTagBService;

    /**
     * 订单标签修改
     *
     * @param message
     */
    @AliyunMQHandler(tags = MessageQueueTagConsts.ORDER_TAG)
    public void addOrder(String message) {
        log.info("#mq#orderTagChange#recive message:{}", message);

        Long workId = null;
        try {
            JSONObject data = JSON.parseObject(message);
            Long orderId = data.getLong("orderId");
            workId = data.getLong("workId");
            Integer logType = data.getInteger("logType");
            orderTagBService.modifyOrderTagByLogType(orderId, workId, logType);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
